1927B - Following the String - CodeForces Solution


constructive algorithms greedy strings

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define vvi vector<vector<int>>
#define endl '\n'
const int base = 31;
const int MOD = 1e9 + 7;
const int maxN = 200006;
using namespace std;
int n, a[maxN];
map<char, int> mp;

void Input() {
	cin >> n;
	mp.clear();
	for(int i = 1; i <= n; i++) cin >> a[i];
}	

void Process() {
	for(int i = 1; i <= n; i++) {
		for(char c = 'a'; c <= 'z'; c++) {
			if (mp[c] == a[i]) {
				cout << c;
				mp[c]++;
				break;
			}
		}
	}
	cout << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int test = 1;
	cin >> test;

	while(test--) {
		Input();
		Process();
	}
	return 0;
}

// special cases (n=1?)
// 2 segments intersect: max(l, L) <= min(r, R)

/*
-Use: ordered_set st;
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
-Use: loang
int X[4] = {0, -1, 1, 0};
int Y[4] = {1, 0, 0, -1};
*/

/*
#######################################
##                                   ##
##             LuOsIer               ##
##                                   ##
#######################################
*/



Comments

Submit
0 Comments
More Questions

810A - Straight A
1433C - Dominant Piranha
633A - Ebony and Ivory
1196A - Three Piles of Candies
299A - Ksusha and Array
448B - Suffix Structures
1092B - Teams Forming
1166C - A Tale of Two Lands
544B - Sea and Islands
152B - Steps
1174D - Ehab and the Expected XOR Problem
1511A - Review Site
1316A - Grade Allocation
838A - Binary Blocks
1515D - Phoenix and Socks
1624D - Palindromes Coloring
1552F - Telepanting
1692G - 2Sort
1191A - Tokitsukaze and Enhancement
903A - Hungry Student Problem
52B - Right Triangles
1712A - Wonderful Permutation
1712D - Empty Graph
1712B - Woeful Permutation
1712C - Sort Zero
1028B - Unnatural Conditions
735B - Urbanization
746C - Tram
1278B - A and B
1353D - Constructing the Array